package cn.itcast.zt.luaLock;

/**
 * @author zhangtian105
 * @ClassName RedisLuaScript.java
 * @projectName Redis
 * @Description 脚本
 * @createTime 2020年11月19日 09:39:00
 */
public interface RedisLuaScript {
    //续租
    public static final String LOCK_LEASE_SCRIPT = "local key = KEYS[1]                            \n"
            + "local value = ARGV[1]                          \n"
            + "local newExpireTime = ARGV[2]                  \n"
            + "                                               \n"
            + "if (redis.call('get',key) == value)  then      \n"
            + "   redis.call('pexpire' , key ,newExpireTime)  \n"
            + "   return 1                               \n"
            + "else                                           \n"
            + "   return 0                              \n"
            + "end                                            \n";

    //解锁
    public static final String UN_LOCK_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
}
